package com.wenyu.wenyuyuedu.adapter.personage;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.bean.personage.MyMessagesBean;
import com.wenyu.wenyuyuedu.bean.personage.SystemMsgBean;
import com.wenyu.wenyuyuedu.utils.TimeStyle;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/25.
 * 我的消息中---评论的adapter
 */

public class MySystemAdapter extends BaseAdapter {
    private List<SystemMsgBean.InfoBean> infoBeen = new ArrayList<>();
    private Context context;

    private MyCollectAdapter.deleteOnclickListener deleteOnclickListener;
    private String id;
    private MyMessagesBean.InfoBean infoBean;

    public void setDeleteOnClickLis(MyCollectAdapter.deleteOnclickListener deleteOnClickLis) {
        this.deleteOnclickListener = deleteOnClickLis;

    }

    public MySystemAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return infoBeen.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        MyCommentViewHolder holder = null;
        if (view == null) {
            holder = new MyCommentViewHolder();
            view = View.inflate(context, R.layout.my_messages_system_item, null);
            holder.system_content = (TextView) view.findViewById(R.id.system_content);
            holder.system_time = (TextView) view.findViewById(R.id.system_time);
            holder.btn_delete = (Button) view.findViewById(R.id.btn_delete);
            view.setTag(holder);
        } else {
            holder = (MyCommentViewHolder) view.getTag();
        }
        SystemMsgBean.InfoBean infoBean = infoBeen.get(i);
        if (infoBean != null) {
            /*系统通知内容*/
            holder.system_content.setText(infoBean.getInform_content());
            /*时间*/
            String pubtime = infoBean.getPubtime();
            String s = TimeStyle.publishTime(pubtime);
            holder.system_time.setText(s);
            holder.btn_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (deleteOnclickListener != null) {
                        deleteOnclickListener.onClick(i, view);
                    }
                }
            });
        }

        return view;
    }

    public List<SystemMsgBean.InfoBean> getList() {
        return infoBeen;
    }

    class MyCommentViewHolder {
        TextView system_content, system_time;
        Button btn_delete;
    }

    public void addAll(List<SystemMsgBean.InfoBean> infoBeen) {
        if (infoBeen != null) {
            this.infoBeen = infoBeen;
            notifyDataSetChanged();
        }
    }

    public void clear() {
        infoBeen.clear();
    }

    public interface deleteOnclickListener {
        void onClick(int position, View view);
    }
}
